/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * jdAdministrarLicitacion.java
 *
 * Created on 04-ago-2010, 11:43:51
 */

package Licitaciones;

import Licitaciones.jifAdministracion;
import administracion.BeanBinding.TblBeanBindingDetalleLicitacion;
import administracion.delegate.GestionPedidosDelegate;
import administracion.helper.Listas;
import administracion.helper.MiTablePrint;
import administracion.helper.Utiles_Fecha;
import administracion.helper.Utiles_MensajesDialogo;
import administracion.helper.Utiles_Tabla;
import administracion.helper.VerificarDatos;
import administracion.propiedades.Propiedades;
import com.jidesoft.hints.ListDataIntelliHints;
import java.awt.Frame;
import java.awt.event.KeyEvent;
import java.math.BigDecimal;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JDialog;
import javax.swing.JFormattedTextField;
import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;
import javax.swing.text.MaskFormatter;
import org.jdesktop.beansbinding.AutoBinding;
import org.jdesktop.beansbinding.BindingGroup;
import org.jdesktop.beansbinding.ELProperty;
import org.jdesktop.swingbinding.JTableBinding;
import org.jdesktop.swingbinding.SwingBindings;
import suministros.ejb30.TO.DetalleLicitacionTO;
import suministros.ejb30.TO.LicitacionTO;
import suministros.ejb30.TO.ProveedorTO;
import suministros.ejb30.TO.TipoTO;
import suministros.ejb30.entity.DetalleLicitacion;
import suministros.ejb30.entity.DetalleLicitacionPK;
import suministros.ejb30.entity.Licitacion;
import suministros.ejb30.entity.Proveedor;
import suministros.ejb30.helper.Utiles_Convertir;

/**
 *
 * @author Diana
 */
public class jdAdministrarLicitacion extends javax.swing.JDialog {
    public List<TblBeanBindingDetalleLicitacion> detalleLicitacionEliminar=new ArrayList<TblBeanBindingDetalleLicitacion>();
    public List<TblBeanBindingDetalleLicitacion> detalleLicitacionAgregar= new ArrayList<TblBeanBindingDetalleLicitacion>();
    Frame padre;
    public List<TblBeanBindingDetalleLicitacion> detalleLicitacion;
    jifAdministracion jifLicitacion;
    private List<DetalleLicitacionTO> detalleLicitacionTO;
    private MaskFormatter mascaraFecha;
    private MaskFormatter mascaraCodigo;
    private JTableBinding jTableBinding;
    private ListDataIntelliHints intelliHintsProveedor;
    private Proveedor proveedor;
    List listaTipos = null;
    String codigo;
    String descripcion;
    String prove;
    String fechaIni;
    String fechaFin;
    String monto;
    jifAdministracion admi;
    LicitacionTO licTO;
    jifAdministracion vpadre;
    List listaTipos2 = new ArrayList();

    /** Creates new form jdAdministrarLicitacion */
    public jdAdministrarLicitacion(jifAdministracion vpadre,java.awt.Frame padre,java.awt.Frame parent, boolean modal,LicitacionTO licTO, String codigo, String descripcion, String prove, String fechaIni, String fechaFin, String monto) {
        super(parent, modal);

        construirMascaras();
        this.padre=padre;
        this.vpadre=vpadre;
        this.codigo=codigo;
        this.descripcion= descripcion;
        this.prove=prove;
        this.fechaIni=fechaIni;
        this.fechaFin= fechaFin;
        this.monto=monto;
        this.detalleLicitacion = new ArrayList(1);
        this.licTO= licTO;
        initComponents();
        this.llenarComboTipoFormaPago();
        this.jtfCodigo.setText(codigo);
        this.jtfDescripcion.setText(descripcion);
        this.jtfRuc.setText(licTO.getRuc());
        buscarRazonSocial();
        this.jtfMonto.setText(monto);
        Utiles_Fecha fec= new Utiles_Fecha(fechaIni, true);
        Utiles_Fecha fec2= new Utiles_Fecha(fechaFin, true);
        this.jftfFechaInicio.setText(fec.getFecha());
        this.jftfFechaFin.setText(fec2.getFecha());
        this.jcboFormaPago.setSelectedItem(this.obtenerFormaPago(licTO.getTipoPago()));
        this.jtfCodigo.setEnabled(false);

        cargarDetalles();
        try {
            cargaHintsIndependientes();
        } catch (Exception ex) {
            Logger.getLogger(jdAdministrarLicitacion.class.getName()).log(Level.SEVERE, null, ex);
        }
        buscarRuc();
    }
    public TipoTO obtenerFormaPago(String nombre){
        TipoTO dep= new TipoTO();
        for(int i=0 ; i<this.listaTipos2.size(); i++){
            if((((TipoTO)listaTipos2.get(i)).getDescripcion_valor().trim()).compareTo(nombre)==0){
                dep= (TipoTO)listaTipos2.get(i);
            }
        }
        return dep;
    }
    private void buscarRuc()
      {
         ProveedorTO pro;
         List listapro=this.intelliHintsProveedor.getCompletionList();
         for(int i=0; i<listapro.size(); i++){
          pro=((ProveedorTO)listapro.get(i));
          if(pro.getRazon().compareTo(this.jtfProveedor.getText())==0){
              this.jtfRuc.setText(pro.getCodProveedor());
          }
         }
      }
    void setPadreDetalleAlmacen(jifAdministracion admi){
        this.admi=admi;
    }
     private void construirMascaras() {
    try {
      this.mascaraFecha = new MaskFormatter("##/##/####");
    } catch (ParseException ex) {
      Logger.getLogger(jdAdministrarLicitacion.class.getName()).log(Level.SEVERE, null, ex);
      ex.printStackTrace();
    }
  }
      public void cargarDetalles(){
        try {
            detalleLicitacionTO = GestionPedidosDelegate.getInstance().getDatosLicitacionDetalles(codigo);
            detalleLicitacion= this.convertirDetalles_Licitacion(detalleLicitacionTO);
        } catch (Exception ex) {
            Logger.getLogger(jdAdministrarLicitacion.class.getName()).log(Level.SEVERE, null, ex);
        }
        actualizaTablaDetalle();

      }
       public List<TblBeanBindingDetalleLicitacion> convertirDetalles_Licitacion( List<DetalleLicitacionTO> listadetalles){
           List<TblBeanBindingDetalleLicitacion> deIngreso= new ArrayList<TblBeanBindingDetalleLicitacion>();
          for(DetalleLicitacionTO deta: listadetalles){
                 TblBeanBindingDetalleLicitacion ing= new TblBeanBindingDetalleLicitacion();
                 ing.setId_suministro(deta.getId_suministro());
                 ing.setDesc_suministro(deta.getDesc_suministro());
                 ing.setCantidad(deta.getCantidad());
                 ing.setCantidadAdquirida(deta.getCantidadAdquirida());
                 ing.setPrecio(deta.getPrecio());
                 ing.setPrecioTotal(deta.getPrecioTotal());
                 ing.setMontoAdquirido(deta.getMontoAdquirido());
                 deIngreso.add(ing);
             }
          return deIngreso;
      }

     private void cargaHintsIndependientes() throws Exception {
    this.intelliHintsProveedor = new ListDataIntelliHints(this.jtfProveedor, Listas.getProveedores());
  }
      private void llenarComboTipo() {
        List listaTipos_cbo1 = this.cboBeanBindingTipo1.getLista();
        listaTipos_cbo1.clear();
        try
        {
          listaTipos = Listas.getTipo_porTabla("tipo_licitacion");
          this.cboBeanBindingTipo1.setLista(listaTipos);
          this.bindingGroup.bind();

        } catch (Exception ex) {
          Utiles_MensajesDialogo.mensajeAlerta("Error al obtener tipos\n" + ex.getMessage());
          ex.printStackTrace();
          Logger.getLogger(jdAdministrarLicitacion.class.getName()).log(Level.SEVERE, null, ex);
        }
      }

 private void llenarComboTipoFormaPago() {
        listaTipos2 = null;
        List listaTipos_cbo2 = this.cboBeanBindingTipo2.getLista();
        listaTipos_cbo2.clear();
        try
        {
          listaTipos2 = Listas.getTipo_porTabla("Tipo_FormaPago");

          this.cboBeanBindingTipo2.setLista(listaTipos2);
          this.bindingGroup.bind();
          this.jcboFormaPago.updateUI();
          this.jcboFormaPago.setSelectedIndex(-1);
        } catch (Exception ex) {
          Utiles_MensajesDialogo.mensajeAlerta("Error al obtener Formas de Pago\n" + ex.getMessage());
          ex.printStackTrace();
          Logger.getLogger(jifRegistrarLicitacion.class.getName()).log(Level.SEVERE, null, ex);
        }
      }

    void agregaDetalleSuministro(TblBeanBindingDetalleLicitacion detalle) throws Exception {
    try {

      if (verificaNoExisteSuministro(detalle)) {
        this.detalleLicitacion.add(detalle);
        actualizaTablaDetalle();
      } else {
        throw new Exception("El suministro " + detalle.getDesc_suministro().trim() + "\nya fue ingresado");
      }
    } catch (Exception e) {
      throw e;
    }
  }
    private boolean verificaNoExisteSuministro(TblBeanBindingDetalleLicitacion detalle) {
    boolean retorno = true;
    for (TblBeanBindingDetalleLicitacion det : this.detalleLicitacion) {
      if (det.getId_suministro().equalsIgnoreCase(detalle.getId_suministro())) {
        retorno = false;
        break;
      }
    }
    return retorno;
  }

     void modificarDetalleSuministro(TblBeanBindingDetalleLicitacion detalle, int posicion) throws Exception {
        try {
            this.detalleLicitacion.set(posicion, detalle);
            actualizaTablaDetalle();

        }catch (Exception e) {
          throw e;
        }
      }
     public void actualizaTablaDetalle() {
        this.bindingGroup = new BindingGroup();
        this.jTableBinding = SwingBindings.createJTableBinding(AutoBinding.UpdateStrategy.READ, this.detalleLicitacion, this.jtDetalleSuministro);

        JTableBinding.ColumnBinding columnBinding0 = this.jTableBinding.addColumnBinding(ELProperty.create("${id_suministro}"));

        columnBinding0.setColumnName("ID Suministro");
        columnBinding0.setColumnClass(String.class);
        columnBinding0.setEditable(false);

        JTableBinding.ColumnBinding columnBinding1 = this.jTableBinding.addColumnBinding(ELProperty.create("${desc_suministro}"));

        columnBinding1.setColumnName("Suministro");
        columnBinding1.setColumnClass(String.class);
        columnBinding1.setEditable(false);

        JTableBinding.ColumnBinding columnBinding2 = this.jTableBinding.addColumnBinding(ELProperty.create("${cantidad}"));

        columnBinding2.setColumnName("Cantidad");
        columnBinding2.setColumnClass(BigDecimal.class);
        columnBinding2.setEditable(true);

        JTableBinding.ColumnBinding columnBinding3 = this.jTableBinding.addColumnBinding(ELProperty.create("${cantidadAdquirida}"));

        columnBinding3.setColumnName("Cant.Adq");
        columnBinding3.setColumnClass(BigDecimal.class);
        columnBinding3.setEditable(true);

        JTableBinding.ColumnBinding columnBinding4 = this.jTableBinding.addColumnBinding(ELProperty.create("${precio}"));

        columnBinding4.setColumnName("Precio");
        columnBinding4.setColumnClass(BigDecimal.class);
        columnBinding4.setEditable(false);

        JTableBinding.ColumnBinding columnBinding5 = this.jTableBinding.addColumnBinding(ELProperty.create("${precioTotal}"));

        columnBinding5.setColumnName("Prec.Total");
        columnBinding5.setColumnClass(BigDecimal.class);
        columnBinding5.setEditable(false);

        JTableBinding.ColumnBinding columnBinding6 = this.jTableBinding.addColumnBinding(ELProperty.create("${montoAdquirido}"));

        columnBinding6.setColumnName("Mont.Adq");
        columnBinding6.setColumnClass(BigDecimal.class);
        columnBinding6.setEditable(false);

        this.bindingGroup.addBinding(this.jTableBinding);
        this.bindingGroup.bind();
         int[] porcentajes= {10,40,10,10,10,10,10};
        try {
            Utiles_Tabla.definirAnchoColumnasJTable(jtDetalleSuministro, porcentajes);
            // MiTablePrint.autoSizeTableColumns(this.jtDetalleSuministro);
        } catch (Exception ex) {
            Logger.getLogger(jdAdministrarLicitacion.class.getName()).log(Level.SEVERE, null, ex);
        }

        
      }
       private void eliminarFila() {
        String id_sumi = this.jtDetalleSuministro.getValueAt(this.jtDetalleSuministro.getSelectedRow(), 0).toString().trim();

        for (TblBeanBindingDetalleLicitacion det : this.detalleLicitacion) {
          if (det.getId_suministro().equalsIgnoreCase(id_sumi)) {
            this.detalleLicitacion.remove(det);
            this.detalleLicitacionEliminar.add(det);
            //jtfMonto.setText(new BigDecimal(jtfMonto.getText()).subtract(det.getPrecioTotal())+"");
            break;
          }
        }
        actualizaTablaDetalle();
      }

     public   void cerrar(){
      int res = javax.swing.JOptionPane.showConfirmDialog( this,"Esta seguro de salir?",
      "Confirmar",javax.swing.JOptionPane.YES_NO_OPTION );
            if(res==javax.swing.JOptionPane.YES_OPTION){
                    this.dispose();

         }
      }
     public boolean modificarLicitacion(){
        boolean estado=true;
        try {

            List<DetalleLicitacion> lista= new ArrayList();
            List<DetalleLicitacion> listaEliminar= new ArrayList();
            List<DetalleLicitacion> listaAgregar= new ArrayList();
            Date fechaFin = new Date(VerificarDatos.verificaFecha(this.jftfFechaFin.getText()).getTime());
            Date fechaInicio = new Date(VerificarDatos.verificaFecha(this.jftfFechaInicio.getText()).getTime());
            if(fechaInicio.after(fechaFin)){
                Utiles_MensajesDialogo.mensajeError("La fecha de fin no puede ser antes que la de inicio");
                estado=false;
            }
            else{
                 licTO.setDescripcion(this.jtfDescripcion.getText());
                 licTO.setFechaIni(this.jftfFechaInicio.getText());
                 licTO.setFechaFin(this.jftfFechaFin.getText());
                 licTO.setMonto(new BigDecimal(this.jtfMonto.getText()));
                 licTO.setProveedor(this.jtfRuc.getText());
                 licTO.setTipoPago(Utiles_Convertir.convertirToTipo_TipoTO((TipoTO) this.jcboFormaPago.getSelectedItem()).getIdTablaTipo()+"");

                 for (TblBeanBindingDetalleLicitacion deta : this.detalleLicitacion) {
                  DetalleLicitacionPK dlpk= new  DetalleLicitacionPK(this.jtfCodigo.getText(), deta.getId_suministro());
                  DetalleLicitacion detall = new DetalleLicitacion();
                  detall.setDetalleLicitacionPK(dlpk);
                  detall.setCantidad(deta.getCantidad());
                  detall.setPrecio(deta.getPrecio());
                  detall.setPrecioTotal(deta.getPrecioTotal());
                  detall.setCantidadAdquirida(deta.getCantidadAdquirida());

                 }
                 for (TblBeanBindingDetalleLicitacion deta : this.detalleLicitacionAgregar) {
                  DetalleLicitacion detall = new DetalleLicitacion(this.jtfCodigo.getText(), deta.getId_suministro());
                  detall.setCantidad(deta.getCantidad());
                  detall.setPrecio(deta.getPrecio());
                  detall.setPrecioTotal(deta.getPrecioTotal());
                  detall.setCantidadAdquirida(deta.getCantidadAdquirida());
                  listaAgregar.add(detall);

                 }
                 for (TblBeanBindingDetalleLicitacion deta : this.detalleLicitacionEliminar) {
                  DetalleLicitacion detall = new DetalleLicitacion(this.jtfCodigo.getText(), deta.getId_suministro());
                  detall.setCantidad(deta.getCantidad());
                  detall.setPrecio(deta.getPrecio());
                  detall.setPrecioTotal(deta.getPrecioTotal());
                  detall.setCantidadAdquirida(deta.getCantidadAdquirida());
                  listaEliminar.add(detall);

                 }
                 BigDecimal sumatotal=BigDecimal.ZERO;
                  for(int i=0; i<detalleLicitacion.size(); i++){

                    BigDecimal monto=detalleLicitacion.get(i).getPrecioTotal();
                    sumatotal=sumatotal.add(monto);
                 }
                if((new BigDecimal(this.jtfMonto.getText())).compareTo(sumatotal)!=0){
                     int res1 = javax.swing.JOptionPane.showConfirmDialog( this,"El monto total '"+this.jtfMonto.getText()+"' no coincide con el ingresado en los detalles '"+sumatotal+"' \n ¿Desea modificar el monto de la licitacion",
                    "Confirmar",javax.swing.JOptionPane.YES_NO_OPTION );
                     if(res1==javax.swing.JOptionPane.YES_OPTION){
                        licTO.setMonto(sumatotal.setScale(2));
                        this.jtfMonto.setText(sumatotal.setScale(2)+"");
                     }
                 }
              GestionPedidosDelegate.getInstance().modificarLicitacion(Propiedades.getUsuario(),Propiedades.getMac(),licTO, lista, listaAgregar,listaEliminar );
              this.jbtnAgregar.setEnabled(true);
              Utiles_MensajesDialogo.mensajeExito();

            }
           
        } catch (Exception ex) {
            Logger.getLogger(jdAdministrarLicitacion.class.getName()).log(Level.SEVERE, null, ex);
        }
        return estado;
     }
     public void consultarLicitacion(){

     }
     private void buscarRazonSocial()
      {
        ProveedorTO pro;
        if (this.jtfRuc.getText().trim().length() < 1) {
              try { pro = (ProveedorTO)this.intelliHintsProveedor.getSelectedHint();
              } catch (NullPointerException ex) {
                pro = null;
              }
            }
        else {
          pro = Listas.getProveedorcodigo(this.jtfRuc.getText().trim());
        }
        if (pro == null) {
          Utiles_MensajesDialogo.mensajeError("El proveedor no existe!");
          this.jtfRuc.setText("");
          pro = null;
        }
        else {
          this.proveedor = Utiles_Convertir.convertirToProveedor_ProveedorTO(pro);
          this.jtfProveedor.setText(pro.getRazon() + " - " + pro.getCodProveedor());
          this.jtfRuc.setText(pro.getCodProveedor());
        }

      }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        cboBeanBindingAno1 = new administracion.BeanBinding.CboBeanBindingAno();
        cboBeanBindingTipo1 = new administracion.BeanBinding.CboBeanBindingTipo();
        cboBeanBindingTipo2 = new administracion.BeanBinding.CboBeanBindingTipo();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jtfDescripcion = new javax.swing.JTextField();
        jtfMonto = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtDetalleSuministro = new javax.swing.JTable();
        this.jtDetalleSuministro.getTableHeader().setReorderingAllowed(false) ;
        jbAgregarDetalle = new javax.swing.JButton();
        jbEliminaDetalle = new javax.swing.JButton();
        jbtMoficar = new javax.swing.JButton();
        jbtnAgregar = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jftfFechaFin = new JFormattedTextField(this.mascaraFecha);
        jftfFechaInicio = new JFormattedTextField(this.mascaraFecha);
        jtfRuc = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jtfProveedor = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jtfCodigo = new javax.swing.JFormattedTextField();
        jcboFormaPago = new javax.swing.JComboBox();
        jbCancelar = new javax.swing.JButton();
        jbAceptar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("ADMINISTRAR LICITACIONES");

        jLabel1.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel1.setText("CODIGO DE PROCESO:");

        jLabel2.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel2.setText("DESCRIPCION DE PROCESO:");

        jLabel3.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel3.setText("FECHA INICIO:");

        jLabel4.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel4.setText("FECHA FIN:");

        jLabel5.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel5.setText("MONTO TOTAL:");

        jLabel7.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel7.setText("PROVEEDOR:");

        jtfDescripcion.setFont(new java.awt.Font("Arial", 0, 12));

        jtfMonto.setFont(new java.awt.Font("Arial", 0, 12));
        jtfMonto.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jtfMontoFocusGained(evt);
            }
        });
        jtfMonto.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jtfMontoKeyPressed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("SUMINISTROS ASIGNADOS"));

        jtDetalleSuministro.setFont(new java.awt.Font("Arial", 0, 12));
        jtDetalleSuministro.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "CODIGO", "DENOMINACION", "CANTIDAD", "CANTIDAD ADQUIRIDA", "PRECIO", "PRECIO TOTAL", "MONTO ADQUIRIDO"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane2.setViewportView(jtDetalleSuministro);

        jbAgregarDetalle.setFont(new java.awt.Font("Arial", 1, 12));
        jbAgregarDetalle.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/add.png"))); // NOI18N
        jbAgregarDetalle.setMnemonic('G');
        jbAgregarDetalle.setText("AGREGAR");
        jbAgregarDetalle.setToolTipText("Agregar un detalle al pedido");
        jbAgregarDetalle.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jbAgregarDetalle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbAgregarDetalleActionPerformed(evt);
            }
        });
        jbAgregarDetalle.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jbAgregarDetalleKeyPressed(evt);
            }
        });

        jbEliminaDetalle.setFont(new java.awt.Font("Arial", 1, 12));
        jbEliminaDetalle.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/remove.png"))); // NOI18N
        jbEliminaDetalle.setMnemonic('E');
        jbEliminaDetalle.setText("ELIMINAR");
        jbEliminaDetalle.setToolTipText("Eliminar el detalle seleccionado");
        jbEliminaDetalle.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jbEliminaDetalle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbEliminaDetalleActionPerformed(evt);
            }
        });
        jbEliminaDetalle.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jbEliminaDetalleKeyPressed(evt);
            }
        });

        jbtMoficar.setFont(new java.awt.Font("Arial", 1, 12));
        jbtMoficar.setText("MODIFICAR");
        jbtMoficar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtMoficarActionPerformed(evt);
            }
        });

        jbtnAgregar.setFont(new java.awt.Font("Arial", 1, 12));
        jbtnAgregar.setText("AÑADIR ACT.");
        jbtnAgregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnAgregarActionPerformed(evt);
            }
        });

        jButton1.setFont(new java.awt.Font("Arial", 1, 12));
        jButton1.setText("MODIFICAR ACT.");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 638, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton1)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jbtMoficar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jbEliminaDetalle, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jbAgregarDetalle, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jbtnAgregar))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jbAgregarDetalle)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbEliminaDetalle)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbtMoficar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbtnAgregar)
                        .addGap(11, 11, 11)
                        .addComponent(jButton1))
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 203, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jButton1, jbAgregarDetalle, jbEliminaDetalle, jbtMoficar, jbtnAgregar});

        jftfFechaFin.setToolTipText("Fecha de Fin");
        jftfFechaFin.setFont(new java.awt.Font("Arial", 0, 12));
        jftfFechaFin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jftfFechaFinActionPerformed(evt);
            }
        });

        jftfFechaInicio.setToolTipText("Fecha de Inicio");
        jftfFechaInicio.setFont(new java.awt.Font("Arial", 0, 12));
        jftfFechaInicio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jftfFechaInicioActionPerformed(evt);
            }
        });

        jtfRuc.setFont(new java.awt.Font("Arial", 0, 12));
        jtfRuc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfRucActionPerformed(evt);
            }
        });

        jLabel6.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel6.setText("RUC:");

        jtfProveedor.setFont(new java.awt.Font("Arial", 0, 12));
        jtfProveedor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfProveedorActionPerformed(evt);
            }
        });
        jtfProveedor.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jtfProveedorKeyPressed(evt);
            }
        });

        jLabel11.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel11.setText("PLAZO DE PAGO:");

        jtfCodigo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jtfCodigoKeyPressed(evt);
            }
        });

        jcboFormaPago.setFont(new java.awt.Font("Arial", 0, 12));

        org.jdesktop.beansbinding.ELProperty eLProperty = org.jdesktop.beansbinding.ELProperty.create("${lista}");
        org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, cboBeanBindingTipo2, eLProperty, jcboFormaPago);
        bindingGroup.addBinding(jComboBoxBinding);

        jcboFormaPago.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jcboFormaPagoItemStateChanged(evt);
            }
        });
        jcboFormaPago.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jcboFormaPagoKeyPressed(evt);
            }
        });

        jbCancelar.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jbCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/button_cancel.png"))); // NOI18N
        jbCancelar.setMnemonic('C');
        jbCancelar.setText("CERRAR");
        jbCancelar.setToolTipText("Cancelar la Operacion");
        jbCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbCancelarActionPerformed(evt);
            }
        });
        jbCancelar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jbCancelarKeyPressed(evt);
            }
        });

        jbAceptar.setFont(new java.awt.Font("Arial", 0, 12));
        jbAceptar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/button_ok.png"))); // NOI18N
        jbAceptar.setMnemonic('A');
        jbAceptar.setText("ACEPTAR");
        jbAceptar.setToolTipText("Registrar el pedido");
        jbAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbAceptarActionPerformed(evt);
            }
        });
        jbAceptar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jbAceptarKeyPressed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addGap(18, 18, 18)
                        .addComponent(jtfMonto, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addGap(44, 44, 44))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel6)
                                    .addComponent(jLabel2))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jtfCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jtfDescripcion, javax.swing.GroupLayout.PREFERRED_SIZE, 599, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addGap(28, 28, 28)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jftfFechaInicio, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(34, 34, 34)
                                .addComponent(jLabel4)
                                .addGap(18, 18, 18)
                                .addComponent(jftfFechaFin, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(50, 50, 50)
                                .addComponent(jLabel11)
                                .addGap(18, 18, 18)
                                .addComponent(jcboFormaPago, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jtfRuc, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(33, 33, 33)
                                .addComponent(jLabel7)
                                .addGap(4, 4, 4)
                                .addComponent(jtfProveedor, javax.swing.GroupLayout.PREFERRED_SIZE, 462, javax.swing.GroupLayout.PREFERRED_SIZE))))))
            .addGroup(layout.createSequentialGroup()
                .addGap(310, 310, 310)
                .addComponent(jbAceptar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbCancelar))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jtfCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jtfDescripcion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(6, 6, 6)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jtfRuc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel6))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addComponent(jLabel7))
                    .addComponent(jtfProveedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(9, 9, 9)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(4, 4, 4)
                                .addComponent(jLabel3))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(1, 1, 1)
                                .addComponent(jftfFechaInicio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(3, 3, 3)
                                .addComponent(jLabel4))
                            .addComponent(jftfFechaFin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(6, 6, 6)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(6, 6, 6)
                                .addComponent(jLabel5))
                            .addComponent(jtfMonto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jcboFormaPago, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel11))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbCancelar)
                    .addComponent(jbAceptar)))
        );

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbAgregarDetalleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbAgregarDetalleActionPerformed

       jdAgregarDetalleLicitacion jdAgregaDetalle=new jdAgregarDetalleLicitacion(this,padre,true);
            jdAgregaDetalle.setLocationRelativeTo(null);
            jdAgregaDetalle.setPadreDetalle(this);
            jdAgregaDetalle.setVisible(true);
            jdAgregaDetalle.setTitle("Agregar detalles de licitacion");
            this.jbtnAgregar.setEnabled(false);

       
}//GEN-LAST:event_jbAgregarDetalleActionPerformed

    private void jbAgregarDetalleKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jbAgregarDetalleKeyPressed
        
        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jbAgregarDetalle.doClick();
        }
}//GEN-LAST:event_jbAgregarDetalleKeyPressed

    private void jbEliminaDetalleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbEliminaDetalleActionPerformed
       
        try {
            if (this.jtDetalleSuministro.getSelectedRow() < 0) {
                Utiles_MensajesDialogo.mensajeError("Debe elegir un detalle");
                return;
            }
            if (Utiles_MensajesDialogo.mensajeConfirmacion("Esta seguro de eliminar el detalle?"))
                eliminarFila();

        } catch (Exception e) {
            e.printStackTrace();
        }
}//GEN-LAST:event_jbEliminaDetalleActionPerformed

    private void jbEliminaDetalleKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jbEliminaDetalleKeyPressed
       
        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jbEliminaDetalle.doClick();
        }
}//GEN-LAST:event_jbEliminaDetalleKeyPressed

    private void jftfFechaFinActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jftfFechaFinActionPerformed
       
    }//GEN-LAST:event_jftfFechaFinActionPerformed

    private void jftfFechaInicioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jftfFechaInicioActionPerformed
        
}//GEN-LAST:event_jftfFechaInicioActionPerformed

    private void jbAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbAceptarActionPerformed

        int res = javax.swing.JOptionPane.showConfirmDialog( this,"Esta seguro que desea modificar esta licitacion?",
                "Confirmar",javax.swing.JOptionPane.YES_NO_OPTION );
        if(res==javax.swing.JOptionPane.YES_OPTION){
            try {

                if(this.modificarLicitacion());{
                     this.vpadre.consultar();
                     this.detalleLicitacionEliminar.clear();
                     this.detalleLicitacionAgregar.clear();
                     this.detalleLicitacion.clear();
                     this.detalleLicitacionTO.clear();
                }
               
            } catch (Exception ex) {
                Logger.getLogger(jdAdministrarLicitacion.class.getName()).log(Level.SEVERE, null, ex);
                Utiles_MensajesDialogo.mensajeError("No se puedo modificar la licitacion");
            }
        }
}//GEN-LAST:event_jbAceptarActionPerformed

    private void jbAceptarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jbAceptarKeyPressed
       
        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jbAceptar.doClick();
        }
}//GEN-LAST:event_jbAceptarKeyPressed

    private void jbCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbCancelarActionPerformed
       
        cerrar();
}//GEN-LAST:event_jbCancelarActionPerformed

    private void jbCancelarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jbCancelarKeyPressed
       
        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jbCancelar.doClick();
        }
}//GEN-LAST:event_jbCancelarKeyPressed

    private void jbtMoficarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtMoficarActionPerformed
        int filaElegida = this.jtDetalleSuministro.getSelectedRow();
        if (filaElegida < 0) {
          Utiles_MensajesDialogo.mensajeError("Debe elegir un detalle de la licitacion!");
          this.jtDetalleSuministro.requestFocus();
        }
        else{
            TblBeanBindingDetalleLicitacion detalle= this.detalleLicitacion.get(this.jtDetalleSuministro.convertRowIndexToModel(filaElegida));
            jdAgregarDetalleLicitacionMod jdAgregaDetalle=new jdAgregarDetalleLicitacionMod(this,padre,true, filaElegida, detalle);
            jdAgregaDetalle.setLocationRelativeTo(null);
            jdAgregaDetalle.setPadreDetalle(this);
            jdAgregaDetalle.setTitle("Modificar detalles de licitacion");
            jdAgregaDetalle.setVisible(true);
        }

    }//GEN-LAST:event_jbtMoficarActionPerformed

    private void jtfRucActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfRucActionPerformed
        if (this.jtfRuc.getText().trim().length() < 1)
            this.jtfRuc.requestFocus();
        else
            buscarRazonSocial();
}//GEN-LAST:event_jtfRucActionPerformed

    private void jtfProveedorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfProveedorActionPerformed
        buscarRazonSocial();
}//GEN-LAST:event_jtfProveedorActionPerformed

    private void jtfProveedorKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfProveedorKeyPressed
        if (this.jtfRuc.getText().trim().length() > 0)
            this.jtfRuc.setText("");
}//GEN-LAST:event_jtfProveedorKeyPressed

    private void jbtnAgregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnAgregarActionPerformed
        int filaElegida = this.jtDetalleSuministro.getSelectedRow();
        if (filaElegida < 0) {
            Utiles_MensajesDialogo.mensajeError("Debe elegir un suministro!");
            this.jtDetalleSuministro.requestFocus();
        } else{
           
            String codigo1=this.jtfCodigo.getText();
            String suministro=this.jtDetalleSuministro.getValueAt(filaElegida, 0).toString();
            String descripcion1=this.jtDetalleSuministro.getValueAt(filaElegida, 1).toString();
            BigDecimal montoTotalSumi=this.detalleLicitacion.get(filaElegida).getPrecioTotal();
            try {
                if (!GestionPedidosDelegate.getInstance().verificarActividades(codigo1, suministro)) {
                    Utiles_MensajesDialogo.mensajeAlerta("Este suministro ya tiene asignado actividades");
                }
                else{
                    jdAgregarActividadesMod jdAgregaDetalle=new jdAgregarActividadesMod(this,padre,true, codigo1, suministro, descripcion1, filaElegida, montoTotalSumi);
                    jdAgregaDetalle.setLocationRelativeTo(null);
                    jdAgregaDetalle.setPadreDetalle(this);
                    jdAgregaDetalle.setVisible(true);
                }
            } catch (Exception ex) {
                Logger.getLogger(jdAgregarActividadesMod.class.getName()).log(Level.SEVERE, null, ex);
            }
            
        }

    }//GEN-LAST:event_jbtnAgregarActionPerformed

    private void jtfMontoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfMontoKeyPressed

    }//GEN-LAST:event_jtfMontoKeyPressed

    private void jtfMontoFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jtfMontoFocusGained
      this.jbAceptar.setEnabled(true);
    }//GEN-LAST:event_jtfMontoFocusGained

    private void jtfCodigoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfCodigoKeyPressed
   
}//GEN-LAST:event_jtfCodigoKeyPressed

    private void jcboFormaPagoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jcboFormaPagoItemStateChanged
        
}//GEN-LAST:event_jcboFormaPagoItemStateChanged

    private void jcboFormaPagoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jcboFormaPagoKeyPressed

        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jtfMonto.requestFocus();
        }
}//GEN-LAST:event_jcboFormaPagoKeyPressed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        int filaElegida = this.jtDetalleSuministro.getSelectedRow();
        if (filaElegida < 0) {
            Utiles_MensajesDialogo.mensajeError("Debe elegir un suministro!");
            this.jtDetalleSuministro.requestFocus();
        } else{

            String codigo1=this.jtfCodigo.getText();
            String suministro=this.jtDetalleSuministro.getValueAt(filaElegida, 0).toString();
            String descripcion1=this.jtDetalleSuministro.getValueAt(filaElegida, 1).toString();
            BigDecimal montoTotalSumi=this.detalleLicitacion.get(filaElegida).getPrecioTotal();
            try {
                if (!GestionPedidosDelegate.getInstance().verificarActividades(codigo1, suministro)) {
                    jdAdministrarActividades jdAgregaDetalle=new jdAdministrarActividades(this,padre,true, codigo1, suministro, descripcion1, filaElegida, montoTotalSumi);
                    jdAgregaDetalle.setLocationRelativeTo(null);
                    jdAgregaDetalle.setPadreDetalle(this);
                    jdAgregaDetalle.setVisible(true);

                }
                else{
                   Utiles_MensajesDialogo.mensajeAlerta("Este suministro no tiene asignado actividades");
                }
            } catch (Exception ex) {
                Logger.getLogger(jdAgregarActividadesMod.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
    * @param args the command line arguments
    */
   

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private administracion.BeanBinding.CboBeanBindingAno cboBeanBindingAno1;
    private administracion.BeanBinding.CboBeanBindingTipo cboBeanBindingTipo1;
    private administracion.BeanBinding.CboBeanBindingTipo cboBeanBindingTipo2;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JButton jbAceptar;
    private javax.swing.JButton jbAgregarDetalle;
    private javax.swing.JButton jbCancelar;
    private javax.swing.JButton jbEliminaDetalle;
    private javax.swing.JButton jbtMoficar;
    private javax.swing.JButton jbtnAgregar;
    private javax.swing.JComboBox jcboFormaPago;
    private javax.swing.JFormattedTextField jftfFechaFin;
    private javax.swing.JFormattedTextField jftfFechaInicio;
    public javax.swing.JTable jtDetalleSuministro;
    private javax.swing.JFormattedTextField jtfCodigo;
    private javax.swing.JTextField jtfDescripcion;
    public javax.swing.JTextField jtfMonto;
    private javax.swing.JTextField jtfProveedor;
    private javax.swing.JTextField jtfRuc;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

}
